ControlPluginsGui{
	
	var parent, w, window, windowW = 400, windowH = 400, o ,typeNames,typeSelect;
	
	*new{|parentArg|
		^super.new.init(parentArg)
		
	}
	
	init{|parentArg|
		var bounds;
		parent = parentArg;
		
		bounds = Rect(Ripple.getMainWindowBounds.left + 15, Ripple.getMainWindowBounds.top, windowW, windowH);
		
		w = SCWindow("Plugins", bounds);
		w.front;
		window = FlowView.new(w, Rect(0, 0, windowW, windowH));
		window.background_(MPGuiConstants.getBackground);
		window.decorator.gap_(0@0);
		window.decorator.margin_(0@0);
		
		o = SCStaticText(window,windowW@20).string = (" Plugins for control:" + parent.getName.asString );
		o.background_( RippleGuiConstants.getHeaderBarColor );
		
		{
			var contents;			
			
			contents = FlowView.new(window, bounds.width@(bounds.height - 20));
			contents.decorator.margin_(10@0);
			
			contents.decorator.nextLine;
			
			this.addPluginsList(contents);
			
			window.decorator.nextLine;
			
			this.addNewPluginSelector(contents);
			
			this.addDoneButt(contents);
			
		}.value;
		
	}
	
	addPluginsList{|window|
		var plugins, div;
		
		div = window;
		
		plugins = parent.getPlugins;
		
		plugins.do{|plugin|
			//div = FlowView.new(window, 0@60);
			div.decorator.gap_(20@20);
			SCStaticText(div,200@20).string = plugin.class.asString;
			
			
			//edit
			o = SCButton(div,50@20);
			o.states = [
				["edit",Color.grey,Color.white]
			];
			o.action = {|butt|
				plugin.launchGui;
			};
			
			// remove
			o = SCButton(div,50@20);
			o.states = [
				["remove",Color.grey,Color.white]
			];
			o.action = {|butt|
				parent.removePlugin(plugin);
				w.close;
			};
			
		}
		
	}
	
	
	addDoneButt{|view|
	
			var v;
			v = SCButton(view,120@20);
			v.states = [
				["add",Color.grey,Color.white]
			];
			v.action = {|butt|
				var plugin;
				plugin = this.getSelectedType.asString.interpret.new;
				parent.addPlugin(plugin);
				plugin.launchGui;
				w.close;
			};
	}
	
	getSelectedType{
		^typeNames.at(typeSelect.value);	
	}
	
	addNewPluginSelector{|view|
		var types, sbs;
		
		o = SCStaticText(window,windowW@20).string = ("Add a plugin to" + parent.getName.asString );
		
		types = AbstractControlPlugin.subclasses;
		
		typeNames = Array.new(types.size);
		
		types.do{|type|
			typeNames.add(type.name);	
		};
		
		typeNames.postln;
		
		typeSelect = SCPopUpMenu(view,Rect(10,10,180,20));
		typeSelect.items = typeNames;
		typeSelect.background_(Color.white);
		
		
	
	}
	
	
	

}